#!/usr/bin/env python
# coding: utf-8


from os import makedirs
from os import path
from os.path import dirname,join
import os
import env
import config_default
import config_online
import config_offline
from utils.commontools import today_int,today_hour


configs = config_default.configs
LOG_DIR = '/home/crawler/logs/fund_service/checksum/' if env.ENV == 'online' else 'logs/'
LOG_DIR = '{0}{1}-{2}'.format(LOG_DIR, today_int(), today_hour())
LOG_FILE = os.path.join(os.path.dirname(os.path.realpath(dirname(__file__))), LOG_DIR)

try:
    ONLINE = env.ENV and env.ENV == 'online'
    OFFLINE = env.ENV and env.ENV == 'offline'
    if ONLINE:
        configs = config_online.configs
    elif OFFLINE:
        configs = config_offline.configs

    if not path.isdir(LOG_FILE):
        makedirs(LOG_FILE)

    # file folder path
    for file_folder in configs['file'].values():
        if not path.isdir(file_folder):
            makedirs(file_folder)

    # pid_file
    for fi in configs['pid'].values():
        base_dir = dirname(fi)
        if not path.isdir(base_dir):
            makedirs(base_dir)

except ImportError:
    pass
